<?php
/*
	账户变更记录
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	if(isset($_RQ['status']) && $_RQ['status'] !=100){
		$params['status']=intval($_RQ['status']);
		$return['status']=intval($_RQ['status']);
	}else{
		$return['status']=100;
	}
	if(isset($_RQ['uniacid'])){
		$params['uniacid']=intval($_RQ['uniacid']);
		$return['params']['uniacid']=$_RQ['uniacid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','ordersn','uniacid','price','status','groupid','num','day','createtime');
	$list=pdo_getslice('core_account_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
		$item['grouptitle']=pdo_getcolumn('core_account_group',array('id'=>$item['groupid']),'title');
		$item['grouptitle']=$item['grouptitle']?:'开通服务';
		$item['image']=pdo_getcolumn('core_account_group',array('id'=>$item['groupid']),'logo');
		$user=pdo_get('core_users',array('uniacid'=>$item['uniacid']),array('nickname','avatar','name'));
		$user['nickname']=$user['nickname']?:'无';
		$item=array_merge($item,$user);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'站点订单'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'订单标题','type'=>'string'),
			array('title'=>'购买账号_username','type'=>'img_string','img'=>'avatar',
			'data'=>array(
				array('title'=>'账号：','name'=>'name'),
				array('title'=>'昵称：','name'=>'nickname')
				)
			),
			array('name'=>'grouptitle','title'=>'购买的套餐','type'=>'string'),
			array('name'=>'ordersn','title'=>'支付单号','type'=>'string'),
			array('name'=>'price','title'=>'金额','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'detail','title'=>'查看详情'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'站点ID','name'=>'uniacid','help'=>''),
			array('type'=>'radio','width'=>'15','title'=>'支付状态','name'=>'status','options'=>'statuss'),
		),
	);
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	$return['statuss']=array(
		'0'=>'待支付',
		'1'=>'支付成功',
		'2'=>'支付失败',
	);
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$item=pdo_get('core_account_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$statuss=array(
		'0'=>'待支付',
		'1'=>'支付成功',
		'2'=>'支付失败',
	);
	$item['status']=$statuss[$item['status']];
	$pay_types=get_pay_types();
	$item['pay_type']=$pay_types[$item['pay_type']];
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'desc'=>'订单详情',
		'look'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'ordersn','title'=>'支付单号','type'=>'string'),
			array('name'=>'price','title'=>'订单金额','type'=>'string'),
			array('name'=>'status','title'=>'订单状态','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),
	);
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	$account=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','desc','logo','groupid','credit2','endtime'));
	$user=pdo_get('core_users',array('id'=>$_SESSION['uniacid']),array('name','nickname'));
	$return['member']=array_merge($account,$user);
	exi($return);
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('core_account_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=intval($_RQ['id']);
	}
	if(!$del){
		exi('请先选择要删除的订单！','error');
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('core_account_order',array('id'=>$id));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='cancel'){
	$post=get_postdata();	
	$id=intval($post['id']);
	if($id){
		pdo_delete('core_account_order',array('status'=>2),array('id'=>$id));
		exi('取消成功！');		
	}else{		
		exi('取消失败！','error');
	}
}